from modules.admin.models.Orders import Orders
from schemas.ad import Create, Update


class OrderUsedService:
    @staticmethod
    def create(form: Create):
        order = Orders.order_paid().where('id', form.order_id)
        return order

    @staticmethod
    def get_all(current, size):
        data = Ad.paginate(size, current)
        return data

    @staticmethod
    def get_one(Id: int):
        data = Ad.find(Id)
        return data

    @staticmethod
    def get_with_by_name(name: str):
        data = (Ad.with_({'ad_items': lambda q: q.where("status", 'active').order_by('order', 'desc')})
                .where('name', name)
                .where('status', 'active')
                .first())
        return data

    @staticmethod
    def update(form: Update, ad_id: str):
        data = Ad.find(ad_id)
        data.update(form.model_dump())
        return data

    @staticmethod
    def delete(Id):
        data = Ad.find(Id)
        data.delete()
        return data
